package com.situ.day1;
	import java.sql.Connection;
	import java.sql.DriverManager;
	import java.sql.ResultSet;
	import java.sql.SQLException;
	import java.sql.Statement;

	import javax.jws.soap.SOAPBinding.Use;

	/*
	 * JDBC工具类
	 */
	public class JDBCUtil {
		private static final String DRIVER = "com.mysql.jdbc.Driver";
		private static final String URL = "jdbc:mysql://localhost:3306/java1807";
		private static final String USER = "root";
		private static final String PASSWORD = "root";
		
		
		static {
			try {
				//1、记载驱动 Class.forName("");
				Class.forName(DRIVER);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		
		//2、获得连接对象Connection
		public static Connection getConnection() throws SQLException {
			Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
			return connection;
		}
		
		//6、关闭连接
		public static void close(Connection connection, Statement statement, ResultSet resultSet) {
			if (resultSet != null) {
				try {
					resultSet.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

	}


